<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">
      <el-form-item label="供应商" prop="supplierName">
        <el-input v-model="queryParams.supplierName" placeholder="请输供应商"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="到货日期">
        <el-date-picker v-model="dateRange"
                        style="display: flex;"
                        value-format="yyyy-MM-dd"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="产品编码" prop="goodsCode">
        <el-input v-model="queryParams.goodsCode" placeholder="请输产品编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输产品名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品型号" prop="goodModel">
        <el-input v-model="queryParams.goodModel" placeholder="请输产品型号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight" @sort-change="handleSortChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column sortable label="退货日期" align="center" prop="createTime"/>
      <el-table-column sortable label="供应商名称" align="center" prop="supplierName"/>
      <el-table-column sortable label="产品编码" align="center" prop="goodsSalebuyall.goodsCode"/>
      <el-table-column sortable label="产品名称" align="center" prop="goodsSalebuyall.goodsName"/>
      <el-table-column sortable label="产品型号" align="center" prop="goodsSalebuyall.goodModel"/>
      <el-table-column sortable label="到货数量" align="center" prop="daohuoCount"/>
      <el-table-column sortable label="到货单价" align="center" prop="unitPrice"/>
      <el-table-column sortable label="到货总价" align="center" prop="totalPrice"/>
      <el-table-column sortable align="center" label="退货类型" prop="tuihuoType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fahuo_type" :value="scope.row.tuihuoType"/>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="入库状态" prop="storageState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.storage_state" :value="scope.row.storageState"/>
        </template>
      </el-table-column>
      <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-popconfirm title="确认入库选择的数据项？" @confirm="handleRuku(scope.row)">
            <el-button slot="reference" type="text"  icon="el-icon-check" size="mini">入库
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>
  </div>
</template>

<script>
import {deleteAction, getAction} from '@/api/manage'
import { listTuihuo } from "@/api/develop/lvDaohuoDetail";

export default {
  name: "TuihuoList",
  dicts: ['inspect_state','storage_state','fahuo_type'],
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购单表格数据
      dataList: [],
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        params:{},
        nos: null,
        arrivalDate: null,
        supplierName: null,
        goodsCode: null,
        goodsName: null,
        goodModel: null,
        createTime: null,
        inspectState: "1",
        //storageState: "0",
        orderByColumn: "createTime",
        isAsc: "desc"
      },
      url: {
        list: '/lvDaohuoDetail/lvDaohuoDetail/listTuihuo',
        ruku: '/lvDaohuoDetail/lvDaohuoDetail/ruku/',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    this.getList();
    window.addEventListener('resize', this.getTableHeight);
  },
  destroyed() {
    window.removeEventListener('resize', this.getTableHeight)
  },
  methods: {
    /** 查询采购单列表 */
    getList() {
      this.loading = true;
      listTuihuo(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
     /** 排序触发事件 */
     handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    /** 入库按钮操作 */
    handleRuku(row) {
      const ids = row.id || this.ids;
      getAction(this.url.ruku+ids, {}).then(response => {
        this.getList();
        this.$modal.msgSuccess("入库成功！");
      }).catch(() => {
      });
    },
    handlerukuAll() {
      const ids = this.ids;
      getAction(this.url.ruku+ids, {}).then(response => {
        this.getList();
        this.$modal.msgSuccess("入库成功！");
      }).catch(() => {
      });
    },
  }
};
</script>
